
#ifndef _CTHREAD_READ_WRITE_GUARD_H_
#define _CTHREAD_READ_WRITE_GUARD_H_ 

#include "read_write_mutex.h"

#include <assert.h>
#include <pthread.h>

namespace CThread
{

class RWGuard 
{
public:
	RWGuard(ReadWriteMutex& value, bool bWrite = false) : rw_mutex_(value) 
	{
		if ( bWrite )
		{
			rw_mutex_.acquireWrite();
		} 
		else
		{
			rw_mutex_.acquireRead();
		}
    }
    ~RWGuard()
	{
		rw_mutex_.release();
    }
 private:
    ReadWriteMutex& rw_mutex_;
};


};

#endif // #ifndef _CTHREAD_READ_WRITE_GUARD_H_
